package cc.yugu.yhdw.webserver.web.controller.security.hdw;

import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.domain.hdw.Bicycle;
import cc.yugu.yhdw.common.entity.json.DataResult;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.json.PageResult;
import cc.yugu.yhdw.webserver.constant.AppConstEnum;
import cc.yugu.yhdw.webserver.service.hdw.BatteryReportLogService;
import cc.yugu.yhdw.webserver.service.hdw.BicycleService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping(value = "/security/hdw/bicycle")
public class BicycleController extends SecurityController {
    @Autowired
    BicycleService bicycleService;
    @Autowired
BatteryReportLogService batteryReportLogService;
    @RequestMapping(value = "index.htm")
    public void index(Model model) {
        model.addAttribute(MENU_CODE_NAME, AppConstEnum.Menu.MENU_03_04.getValue());
    }

    @RequestMapping(value = "page.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public PageResult page(Bicycle bicycle) {
        return PageResult.successResult(bicycleService.findPage(bicycle));
    }

    @RequestMapping(value = "view.htm")
    public String view(Model model, String id) {
        Bicycle entity = bicycleService.find(id);
        if (entity == null) {
            return SEGMENT_RECORD_NOT_FOUND;
        } else {
            model.addAttribute("entity", entity);
        }
        return "/security/hdw/bicycle/view";
    }

    @RequestMapping(value = "bicycle_location.htm")
    public void bicycle_location(Model model, String id) {
        Bicycle entity = bicycleService.find(id);
        model.addAttribute("id", id);
        model.addAttribute("lng", entity.getLng());
        model.addAttribute("lat", entity.getLat());
        model.addAttribute("orderList", batteryReportLogService.findOrderId(null,id));
    }

    @RequestMapping("delete.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult delete(String id) {
        bicycleService.delete(id);
        return ExtResult.successResult();
    }

}
